﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;

namespace chlnge
{
    class Currencies
    {
        private int currencyId;
        private string currencyName;
        private string ticker;

        public Currencies(int currencyId, string currencyName, string ticker)
        {
            this.currencyId = currencyId;
            this.currencyName = currencyName;
            this.ticker = ticker;
        }

        public int PCurrencyId
        {
            get
            {
                return currencyId;
            }
            set
            {
                currencyId = value;
            }
        }

        public string PCurrencyName
        {
            get
            {
                return currencyName;
            }
            set
            {
                currencyName = value;
            }
        }

        public string PTicker
        {
            get
            {
                return ticker;
            }
            set
            {
                ticker = value;
            }
        }

        public static List<Currencies> GetCurrencies() 
        {
            string connString = "Server = localhost; Database = productsinformation; Uid = root; password = valerieva";

            MySqlConnection conn = new MySqlConnection(connString);
            List<Currencies> currencies = new List<Currencies>();
            MySqlCommand command = conn.CreateCommand();
            command.CommandText = GenerateQuerry();

            using (conn)
            {
                conn.Open();
                MySqlDataReader reader = command.ExecuteReader();
                using (reader)
                {
                    while (reader.Read())
                    {
                        currencies.Add(new Currencies((int)reader["currencyId"], (string)reader["currencyName"],
                            (string)reader["ticker"]));
                    }
                }
            }
            return currencies;
        }

        private static string GenerateQuerry()
        {
            return "Select * From currencies";
        }
    }
}
